Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

splits out gossip CrdsData out of crds_value.rs #3463

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

behzadnouri
Copy link

Problem

Reorganizing this code in preparation of upcoming changes to CrdsValue (de)serialization.

Summary of Changes

split out gossip CrdsData out of crds_value.rs

@behzadnouri behzadnouri force-pushed the split-crds-data branch 4 times, most recently from ca2f999 to 4d4be4d Compare November 4, 2024 19:23
Comment on lines +139 to +176
pub(crate) fn wallclock(&self) -> u64 {
match self {
CrdsData::LegacyContactInfo(contact_info) => contact_info.wallclock(),
CrdsData::Vote(_, vote) => vote.wallclock,
CrdsData::LowestSlot(_, obj) => obj.wallclock,
CrdsData::LegacySnapshotHashes(hash) => hash.wallclock,
CrdsData::AccountsHashes(hash) => hash.wallclock,
CrdsData::EpochSlots(_, p) => p.wallclock,
CrdsData::LegacyVersion(version) => version.wallclock,
CrdsData::Version(version) => version.wallclock,
CrdsData::NodeInstance(node) => node.wallclock,
CrdsData::DuplicateShred(_, shred) => shred.wallclock,
CrdsData::SnapshotHashes(hash) => hash.wallclock,
CrdsData::ContactInfo(node) => node.wallclock(),
CrdsData::RestartLastVotedForkSlots(slots) => slots.wallclock,
CrdsData::RestartHeaviestFork(fork) => fork.wallclock,
}
}

pub(crate) fn pubkey(&self) -> Pubkey {
match &self {
CrdsData::LegacyContactInfo(contact_info) => *contact_info.pubkey(),
CrdsData::Vote(_, vote) => vote.from,
CrdsData::LowestSlot(_, slots) => slots.from,
CrdsData::LegacySnapshotHashes(hash) => hash.from,
CrdsData::AccountsHashes(hash) => hash.from,
CrdsData::EpochSlots(_, p) => p.from,
CrdsData::LegacyVersion(version) => version.from,
CrdsData::Version(version) => version.from,
CrdsData::NodeInstance(node) => node.from,
CrdsData::DuplicateShred(_, shred) => shred.from,
CrdsData::SnapshotHashes(hash) => hash.from,
CrdsData::ContactInfo(node) => *node.pubkey(),
CrdsData::RestartLastVotedForkSlots(slots) => slots.from,
CrdsData::RestartHeaviestFork(fork) => fork.from,
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to this exact PR, but why are pubkey and wallclock private in ContactInfo and LegacyContactInfo but public in the other CrdsData types

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of these variants are defined in this same module.
So even if they were private, this code could still access them directly.

gossip/src/crds_data.rs Outdated Show resolved Hide resolved
if let CrdsData::NodeInstance(value) = value.data() {
if let Some(out) = value.overrides(&other.value) {
return out;
match value.data() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we just pass data: &CrdsData into this function instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we pass CrdsData, it kind of obfuscates {ContactInfo,NodeInstance}::overrides api.
Might be more self-explanatory if the api uses a more specific type;

Reorganizing this code in preparation of upcoming changes to CrdsValue
(de)serialization.
Copy link

@gregcusack gregcusack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@behzadnouri behzadnouri merged commit e7778eb into anza-xyz:master Nov 4, 2024
40 checks passed
@behzadnouri behzadnouri deleted the split-crds-data branch November 4, 2024 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants